

import { todogetuserinfo, todogettmsbanners, todogetmyinterviews } from '@/api/api'
import { ShowError } from '@/utils/message'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  plugins: [
  ],
  state: {
    userInfo: null,
    hbanners: [],
    myms: [],
  },
  actions: {
    async getMyMsListAsync({ commit }) {
      let res = await todogetmyinterviews()
      if (res.code == 200) {
        commit('getMyMissList', res.result)
      }
    },
    async getUserInfoAsync({ commit }, payload) {
      let res = await todogetuserinfo()
      if (res.code == 200) {
        commit("getUesrInfoData", res.result)
      } else {
        commit('getUesrInfoData', null)
        ShowError(res.msg)
      }
    },
    async getHomeBannerAsync({ commit }, payload) {
      let res = await todogettmsbanners()
      if (res.code == 200) {
        commit('setHomeBanners', res.result)
      }
    }
  },
  getters: {

  },
  mutations: {
    getMyMissList(state, payload) {
      state.myms = payload;
    },
    setHomeBanners(state, payload) {
      state.hbanners = payload;
    },
    getUesrInfoData(state, payload) {
      state.userInfo = payload;
    },
    changeCount(state, payload) {
      state.count += payload;
    },
    changeMsg(state, payload) {
      state.msg = payload;
    }
  },
  modules: {

  }
})

export default store
